<?php

/** 
 * Copyright (c) 2012, Jiehun.com.cn Inc. All Rights Reserved
 * @author huqingping@jiehun.com.cn
 * @date 2012-2-11
 * @version 1.0 
 * @brief 
 *  
 **/

final class Com
{
	static $_conf;
	static $_cache = array();
	
	static function init($conf)
	{
		self::$_conf = $conf;
	}
	
	static function get($mod)
	{
		if (isset(self::$_cache[$mod])) {
			return self::$_cache[$mod];
		}
		if (!isset(self::$_conf[$mod])) {
			throw new Exception("com.$mod missing conf");
		}
		$class = ucfirst($mod);
		require_once dirname(__FILE__)."/../$mod/$class.php";
		$cf = self::$_conf[$mod];
		if (!empty(self::$_conf['log_func'])) {
			$cf['log_func'] = self::$_conf['log_func'];
		}
		$obj = new $class($cf);
		self::$_cache[$mod] = $obj;
		return $obj;
	}
}
